package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.come.model.Eshop;
import org.come.mouslisten.ShopingImgBorderMosulisten;
import org.come.until.CutButtonImage;
import org.come.until.GoodsListFromServerUntil;

import com.tool.btn.ShopBuyBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

public class RechargeLeftGoodsJpanel extends JPanel {

	private ShopBuyBtn btnBuy;// 购买按钮
	private JLabel labBorder,// 背景框
			labImg;// 特效图片展示
	private String name,// 特效名字
			value,// 价值多少仙玉
			buyTime; // 购买次数
	private Eshop eshop; // 当前的商品
	private ImageIcon icon = CutButtonImage.getImage("inkImg/number/b8/goodsk1.png", -1, -1);
	private ShopingImgBorderMosulisten shopingImgBorderMosulisten;

	public RechargeLeftGoodsJpanel(Eshop eshop) {

			icon = CutButtonImage.getImage("inkImg/number/b8/goodsk1.png", -1, -1);
			this.setPreferredSize(new Dimension(77, 85));
			this.setLayout(null);
			this.setOpaque(true);
			this.setBackground(UIUtils.Color_BACK);

			shopingImgBorderMosulisten = new ShopingImgBorderMosulisten(eshop);
			// 特效图片展示
			labImg = new JLabel();
			labImg.setBounds(0, 0, 85, 85);
			labImg.addMouseListener(shopingImgBorderMosulisten);
			this.add(labImg);
			// 背景框
			labBorder = new JLabel();
			labBorder.setBounds(0, 0, 85, 85);
			labBorder.setIcon(icon);
			this.add(labBorder);

			// 购买按钮
			btnBuy = new ShopBuyBtn("inkImg/hongmu/2/文字按钮_购买_w34,h51.png", 1, "", 10, eshop);
			btnBuy.setBounds(100, 70, 34, 17);
			this.add(btnBuy);

	}

	@Override
	protected void paintComponent(Graphics g) {
		// TODO Auto-generated method stub
		super.paintComponent(g);
		g.setFont(UIUtils.TEXT_FONT2);
		g.setColor(Color.white);
		if (name != null) {
            g.drawString(name, 100, 18);
        }
		g.setColor(Color.red);
		if (value != null) {
            g.drawString(value + "仙玉", 100, 38);
        }
		g.setColor(Color.white);
		if (buyTime != null) {
			g.drawString(buyTime + "次数", 100, 58);
		}
	}

	/**
	 * 清空界面的方法
	 */
	public void clearWindow() {
		name = "";
		value = "";
		labImg.setIcon(null);
		btnBuy.setBtn(0);
		btnBuy.setIcon(null);
		btnBuy.setText("");
		labBorder.setIcon(null);
		shopingImgBorderMosulisten.setEshop(null);
		btnBuy.setEshop(null);
	}

	/** 根据物品添加数据 */
	public void addEshopMessage(Eshop eshop) {
		if (eshop == null) {
			return;
		}
			name = eshop.getEshopname();
			value = eshop.getEshopprice();
			labImg.setIcon(GoodsListFromServerUntil.imgpathAdaptive(eshop.getEshopskin(), 90, 90));
			btnBuy.setBtn(1);
			try {
				btnBuy.setIcons(CutButtonImage.cuts("inkImg/hongmu/2/文字按钮_购买_w34,h51.png"));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			icon = CutButtonImage.getImage("inkImg/old/background/50.png", -1, -1);
			labBorder.setIcon(icon);
			shopingImgBorderMosulisten.setEshop(eshop);
			btnBuy.setEshop(eshop);

	}

	public ShopBuyBtn getBtnBuy() {
		return btnBuy;
	}

	public void setBtnBuy(ShopBuyBtn btnBuy) {
		this.btnBuy = btnBuy;
	}

	public JLabel getLabImg() {
		return labImg;
	}

	public void setLabImg(JLabel labImg) {
		this.labImg = labImg;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public JLabel getLabBorder() {
		return labBorder;
	}

	public void setLabBorder(JLabel labBorder) {
		this.labBorder = labBorder;
	}

	public ShopingImgBorderMosulisten getShopingImgBorderMosulisten() {
		return shopingImgBorderMosulisten;
	}

	public void setShopingImgBorderMosulisten(ShopingImgBorderMosulisten shopingImgBorderMosulisten) {
		this.shopingImgBorderMosulisten = shopingImgBorderMosulisten;
	}

	public Eshop getEshop() {
		return eshop;
	}

	public void setEshop(Eshop eshop) {
		this.eshop = eshop;
	}

}
